package com.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncAnnotationAdvisor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Configuration
public class AsyncConfig {

    @Bean
    public ExecutorService executorService() {
        return Executors.newFixedThreadPool(2);
    }

    /**
     * 注册异步执行的切面
     *
     * @return
     */
    @Bean
    public AsyncAnnotationAdvisor asyncAnnotationAdvisor() {

        final AsyncAnnotationAdvisor advisor = new AsyncAnnotationAdvisor(executorService(), null);
        //advisor.setOrder();
        return advisor;
    }
}
